package cn.elane.elastic.global.config;

import cn.elane.elastic.global.jdbc.Dao;
import cn.elane.elastic.global.model.NameBean;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author Chenyu
 */
@Component
public class AfterStart implements ApplicationRunner, CommandLineRunner {

	@Override
	public void run(ApplicationArguments args) {
		System.out.print("\r\n========================================\r\n========================================\r\n");
		System.out.print("欢迎使用Elane管理系统");
		System.out.print("\r\n========================================\r\n========================================\r\n");
		testDb();
	}

	@Override
	public void run(String... args) {
		System.out.println("run......" + Arrays.toString(args));
	}

	/**
	 * 初始化数据库连接池.
	 */
	private void testDb() {
		NameBean date;
		Dao dao = new Dao();
		try {
			date = dao.find("SELECT SYSDATE() date from dual");
			System.out.println("\r\n========================================\r\n"
					+ date.str("date")
					+ "\r\n========================================");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			date = null;
		}
	}

}
